<%@ page language="java" contentType="text/html; charset=euc-kr" %>
<%@ page import = "java.sql.*, java.util.*" %>
<% request.setCharacterEncoding("euc-kr"); %>

<%
String num = request.getParameter("num");
String name = request.getParameter("plus_name");  
String contents = request.getParameter("plus_contents");
int num_plus = 0;

Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/old_project";
Connection conn = DriverManager.getConnection(url,"root","1397aa");

Statement stmt = conn.createStatement();

String strSQL = "SELECT num FROM pic_plus ORDER BY num DESC";
ResultSet rs = stmt.executeQuery(strSQL);

if(rs.wasNull())  
	num_plus = 1;
else {
    	strSQL = "SELECT Max(num) FROM pic_plus";
    	rs = stmt.executeQuery(strSQL);
    	rs.next();
    	num_plus = rs.getInt(1) + 1;
}

Calendar dateIn = Calendar.getInstance();
String indate = Integer.toString(dateIn.get(Calendar.YEAR)) + "-";
indate = indate + Integer.toString(dateIn.get(Calendar.MONTH)+1) + "-";
indate = indate + Integer.toString(dateIn.get(Calendar.DATE)) + " ";
indate = indate + Integer.toString(dateIn.get(Calendar.HOUR_OF_DAY)) + ":";
indate = indate + Integer.toString(dateIn.get(Calendar.MINUTE)) + ":";
indate = indate + Integer.toString(dateIn.get(Calendar.SECOND));

strSQL ="INSERT INTO pic_plus (num,id, name, contents, writedate)";
strSQL = strSQL +  "VALUES('" + num_plus + "', '" + num + "', '" + name + "',";
strSQL = strSQL +  "'" + contents + "', '" + indate + "')";
stmt.executeUpdate(strSQL);

stmt.close();
conn.close();

response.sendRedirect("write_output.jsp?num=" + num); 
%>